package de.fstyle.test.spring.property.source.order;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { 
	"de.fstyle.test.spring.property.source.order.controller",
})
@PropertySource(
		value = {
			"config/test.a.properties",
			"config/test.b.properties",
			"config/test.c.properties",
			"config/test.d.properties",
		})
public class PropertySourceConfigurer extends WebMvcConfigurerAdapter {

	@Value("${test.prop}")
	private String testProp;

	@Bean
	public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
		return new PropertySourcesPlaceholderConfigurer();
	}

	@Bean
	public TestBean getTestBean() {
		return new TestBean(this.testProp);
	}
	
	public static class TestBean {

		private String testProp;
		
		public TestBean(String testProp) {
			this.testProp = testProp;
		}
		
		public String getTestProp() {
			return testProp;
		}
		
		public void setTestProp(String testProp) {
			this.testProp = testProp;
		}
	}
}
